package com.allwees.bs.core.model.user.entity;

import com.allwees.bs.core.model.coupon.constant.ECouponUseType;
import com.allwees.bs.core.model.coupon.entity.CouponDefModel;
import com.allwees.bs.core.model.user.constant.ECouponDefType;
import com.allwees.bs.core.modelbase.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.MappedSuperclass;
import java.math.BigDecimal;
import java.util.Date;

@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@MappedSuperclass
public abstract class UserCouponModel extends BaseEntity {

    private static final long serialVersionUID = -6655345390535123041L;

    @Column(length = 64)
    protected String no;

    @Column(length = 64)
    protected String userUuid;

    /** 领取日期 **/
    protected Date receiveDate;

    /** 有效期截止日 **/
    protected Date overdueTime;

    // 优惠券信息
    @Column(length = 48)
    protected String couponUuid;

    @Column(length = 255)
    protected String couponName;

//    @Column(length = 96)
//    protected String couponNo;

    @Column(length = 96)
    @Enumerated(EnumType.STRING)
    protected ECouponUseType couponUseType;

    @Column(length = 48)
    @Enumerated(EnumType.STRING)
    protected ECouponDefType couponType;

    protected BigDecimal faceValue;

    /** 最大抵扣金额 **/
    protected BigDecimal maxDeductAmt;

//    protected String promoCode;

    protected String valueText;

    public UserCouponModel(CouponDefModel couponDef, Date receiveDate) {
        this.couponUuid = couponDef.getUuid();
        this.couponName = couponDef.getName();
//        this.couponNo = couponDef.getNo();
        this.couponType = couponDef.getType();
        this.couponUseType = couponDef.getUseType();
        this.faceValue = couponDef.getFaceValue();
        this.maxDeductAmt = couponDef.getMaxDeductAmt();

        this.overdueTime = couponDef.overdueTime(receiveDate);
        this.valueText = couponDef.getValueText();
    }
}
